/**
 * example01.cc 
 *   提取特征，生成simhash值
 */ 
#include <iostream>
#include <fstream>
#include <bitset>
#include "simhash/Simhasher.hpp"    // 包含

using namespace simhash;

int main(int argc, char** argv)
{
    Simhasher simhasher;
    string content = "我是蓝翔技工拖拉机学院手扶拖拉机专业的。不用多久，我就会升职加薪，当上总经理，出任CEO，走上人生巅峰。";
    
    // 提取特征 
    size_t topN = 5;
    vector<pair<string ,double>> features;
    simhasher.extract(content, features, topN);

    for (const auto& [feature, weight] : features) { 
    	cout << feature << ": " << weight << "\n";
    }

    // 生成simhash值
    uint64_t hashcode;
    simhasher.make(content, topN, hashcode); // 包含extract过程

    cout<< "simhash值是: " << hashcode <<endl;
    string s;
    Simhasher::toBinaryString(hashcode, s);
    cout << "二进制序列: " << s << "\n";
    cout << "二进制序列: " << bitset<64>(hashcode) << endl;

    // 比较simhash值得汉明距离
    uint64_t h1 = 17831459094038722629UL;
    uint64_t h2 = 17831459094038722628UL;
    uint64_t h3 = 9876543210UL;
    cout << std::boolalpha  << Simhasher::isEqual(h1, h2) << endl;      // 默认编辑距离是3
    cout << std::boolalpha  << Simhasher::isEqual(h1, h2, 1) << endl;   // 指定编辑距离为1
    cout << std::boolalpha  << Simhasher::isEqual(h1, h3, 5) << endl;   
}